fix(operator_qa): 修复 OperatorQA 工作流中 RAG Service 因缺失 API Key 导致检索失败的问题 #9
+14
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
问题描述
在
OperatorQA工作流中,OperatorRAGService是在工厂函数create_operator_qa_graph中初始化的。由于初始化时没有传入 API Key(且环境变量可能未设置),导致rag_service实例中的 API Key 为空。虽然用户在前端/Request 中传入了 API Key 并存储在
state中,但由于闭包作用域隔离,rag_service无法感知到state中的 Key。这导致在执行
search_operators工具时,底层调用 Embedding 模型失败,报错如下:解决方案
在 wf_operator_qa.py 的 operator_qa_node 节点执行逻辑中添加了状态同步逻辑:
从当前的 state.request.api_key 获取 API Key。
检查 rag_service 是否缺少 Key 或 Key 不一致。
如果需要,将 state 中的 Key 注入到 rag_service 中,并重置其内部的 _searcher 以便使用新 Key 重新懒加载。
验证结果
修复前: 调用工具失败,日志报错 RAG 检索失败,LLM 无法获取相关算子。


修复后: 日志显示 RAG 检索成功,并正确返回算子列表:
